/*
 * @Descripttion: 
 * @version: 
 * @Author: TT
 * @Date: 2023-10-25 16:49:15
 * @LastEditors: TT
 * @LastEditTime: 2023-10-28 11:41:43
 */

import 'package:flutter/material.dart';
import 'package:hzy_project_template/config/config_index.dart';
import 'package:hzy_project_template/models/normal_tool_btn_model.dart';

import 'package:hzy_project_template/pages/root/root_v.dart';
import 'package:hzy_project_template/utils/utils_index.dart';
import 'package:hzy_project_template/base_ui_config/base_ui_config_index.dart';
import '../../commpontents/commpontents_index.dart';

class RootTabWidget extends CommonLessWidget {
  RootTabWidget({super.key});

  final RootC rootC = Get.put(RootC());
  @override
  Widget createBody({
    required BuildContext context,
    BoxConstraints? constraints,
  }) {
    /// 创建tabBar item
    Widget body = GetBuilder<RootC>(
      builder: (controller) => Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: List.generate(
          controller.list.length,
          (index) => configItem(
            index: index,
            tabItemModel: controller.list[index],
            selectIndex: controller.selectIndex,
          ),
        ),
      ),
    );

    /// 创建底部 body
    body = Container(
      height: 49 + SizeMacro.bottomBarHeight,
      padding: EdgeInsets.only(
        bottom: SizeMacro.bottomBarHeight,
      ),
      width: SizeMacro.screenWidth,
      decoration: BoxDecoration(
        color: HzyCommonColor().whitebackgroundColor,
        boxShadow: [
          configShadow(),
        ],
      ),
      child: body,
    );
    return body;
  }

  /// 创建按钮item
  configItem({
    required int index,
    required TabItemModel tabItemModel,
    required int selectIndex,
  }) {
    Widget body = HzyBtnWidget(
      height: 49,
      isFittedBox: false,
      btnLayoutType: BtnLayoutType.topImg,
      textStyle: index == selectIndex
          ? FontConfig.fontMedium12Black
          : FontConfig.fontMedium12Grey,
      imageWidget: configItemImageWidget(
        index: index,
        tabItemModel: tabItemModel,
        selectIndex: selectIndex,
      ),
      text: tabItemModel.text,
      tapCall: () {
        rootC.tapTabItem(index: index);
      },
    );
    body = Expanded(
      child: body,
    );
    return body;
  }

  configItemImageWidget({
    required int index,
    required TabItemModel tabItemModel,
    required int selectIndex,
  }) {
    Widget body = Image.asset(
      selectIndex == index
          ? tabItemModel.selectImagePath!
          : tabItemModel.imagePath!,
      width: 20,
      height: 20,
    );
    return body;
  }
}
